Skip to content

Add FrameworkReference to Microsoft.Aspnetcore.App for non-SharedFx projects with SharedFx-only references#65478

Merged
wtgodbe merged 16 commits intomainfrom
wtgodbe/Vibeit
Feb 27, 2026
Merged

Add FrameworkReference to Microsoft.Aspnetcore.App for non-SharedFx projects with SharedFx-only references#65478
wtgodbe merged 16 commits intomainfrom
wtgodbe/Vibeit

Conversation

@wtgodbe
Copy link
Member

@wtgodbe wtgodbe commented Feb 19, 2026

Fixes #65410

Projects that are are not in the shared framework, ship as packages, and have references to libraries that only ship in the shared framework, should wind up with a FrameworkReference to Microsoft.AspNetCore.App in their .nuspec. We used to have a custom post-build task that injected that FrameworkReference, but that went away in #64863.

This is a bit of a hack - we add a FrameworkReference to the affected projects, so that Restore can put that FrameworkRef into the generated assets file. Then we remove that FrameworkReference prior to ResolveFrameworkReferences so that the ProjectReferences get used instead. We also have to add a IsTransitiveFrameworkReference=true metadata to the FrameworkReference so that pruning warnings don't kick in: https://github.com/dotnet/sdk/blob/e90c4413024970eca97d05122243737aa207af11/src/Tasks/Microsoft.NET.Build.Tasks/GetPackagesToPrune.cs#L103-L104. It would be great if there was metadata we could set on the FrameworkReference (something like "NuspecOnly"), so that none of the references from the FrameworkReference would actually be raised, and pruning warnings wouldn't fire, but the FrameworkRef would still wind up in project.assets.json & the .nuspec.

@github-actions github-actions bot added needs-area-label Used by the dotnet-issue-labeler to label those issues which couldn't be triaged automatically area-infrastructure Includes: MSBuild projects/targets, build scripts, CI, Installers and shared framework and removed needs-area-label Used by the dotnet-issue-labeler to label those issues which couldn't be triaged automatically labels Feb 19, 2026
@wtgodbe wtgodbe changed the title Add FrameworkReference for non-SharedFx projects with SharedFx refs Add FrameworkReference to Microsoft.Aspnetcore.App for non-SharedFx projects with SharedFx-only references Feb 20, 2026
@wtgodbe wtgodbe marked this pull request as ready for review February 20, 2026 22:09
@wtgodbe wtgodbe requested a review from a team as a code owner February 20, 2026 22:09
Copilot AI review requested due to automatic review settings February 20, 2026 22:09
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adjusts the repo’s MSBuild reference-resolution/pack behavior so that non-SharedFx, packable projects that reference SharedFx-only assemblies can surface a Microsoft.AspNetCore.App framework dependency via restore assets (so packing can pick it up).

Changes:

  • Capture the Microsoft.AspNetCore.App KnownFrameworkReference before it’s removed globally, so it can be reintroduced conditionally.
  • Conditionally add a FrameworkReference to Microsoft.AspNetCore.App for packable, non-SharedFx projects with SharedFx-only project references, and add a target to remove the framework reference before ResolveFrameworkReferences.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
eng/targets/ResolveReferences.targets Adds conditional Microsoft.AspNetCore.App framework reference (and re-adds the known framework reference) plus a target that removes the framework reference before ResolveFrameworkReferences.
Directory.Build.targets Captures the KnownFrameworkReference for Microsoft.AspNetCore.App into an internal item before it gets removed.

</PropertyGroup>

<ItemGroup>
<_RemovedAspNetKnownFrameworkReference Include="@(KnownFrameworkReference->WithMetadataValue('Identity', 'Microsoft.AspNetCore.App'))" />
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rather than removing this and adding it back did you consolidating the logic?

@wtgodbe
Copy link
Member Author

wtgodbe commented Feb 26, 2026

/backport to release/11.0-preview2

@github-actions
Copy link
Contributor

Started backporting to release/11.0-preview2 (link to workflow run)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-infrastructure Includes: MSBuild projects/targets, build scripts, CI, Installers and shared framework

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[OpenApi] Microsoft.AspNetCore.OpenApi no longer includes Microsoft.AspNetCore.App framework reference

3 participants